<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Code Documentation &mdash; pyTunesConnect v1.0.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '',
          VERSION:     '1.0.1',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: ''
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/interface.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="contents" title="Global table of contents" href="contents.html" />
    <link rel="index" title="Global index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="pyTunesConnect v1.0.1 documentation" href="index.html" />
    <link rel="prev" title="Web Service Documentation" href="webservice.html" />
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="webservice.html" title="Web Service Documentation"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">pyTunesConnect v1.0.1 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="code-documentation">
<h1 id="code-documentation">Code Documentation<a class="headerlink" href="#code-documentation" title="Permalink to this headline">¶</a></h1>
<p>pyTunesConnect consists of three python source files:</p>
<ul class="simple">
<li>pytunesconnect.py - Contains the Pytunesconnect class and interfaces to appdailysales.py. Could easily be used in other code as a data source. This file is documented below.</li>
<li>pytunescharts.py - Contains code to generate charts, could easily be used in other applications for charting. This file is documented below.</li>
<li>appdailysales.py - This code is part of another open source project, documentation and support can be found here <a class="reference external" href="http://appdailysales.googlecode.com/">http://appdailysales.googlecode.com/</a></li>
</ul>
<div class="section" id="module-pytunesconnect">
<h2 id="module-pytunesconnect">pytunesconnect Class Documentation<a class="headerlink" href="#module-pytunesconnect" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pytunesconnect.Pytunesconnect">
<!--[pytunesconnect.Pytunesconnect]-->class <tt class="descclassname">pytunesconnect.</tt><tt class="descname">Pytunesconnect</tt><big>(</big><em>host='localhost'</em>, <em>user='root'</em>, <em>password='sekret'</em>, <em>name='sales_stats'</em>, <em>table='daily'</em>, <em>url='http://www.mydomain.com/cgi-bin/pytunesconnect.py'</em>, <em>ips=</em><span class="optional">[</span>, <em>'127.0.0.1'</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect" title="Permalink to this definition">¶</a></dt>
<dd><p>The main pytunesconnect class.  You should create one instance of this
object and pass all requests to it.</p>
<p>All values passed in when initializing are optional.  If left blank they
will default to the values set in the &#8220;Default Settings&#8221; section at the
top of the pytunesconnect.py file.</p>
<p>Variable descriptions (all are strings unless specified):</p>
<p>host - The hostname or IP address of the server running the MySQL database.</p>
<p>user - The user used to login to the database server specified by &#8216;host&#8217;</p>
<p>password - The password for the user connecting to the database.</p>
<p>name - Name of the database to connect to on the &#8216;host&#8217;.</p>
<p>table - Name of the table to use in the database.</p>
<p>url - Base URL where pytunesconnect.py is hosted, only needed if using view layer.</p>
<p>ips - &lt;type list&gt; - IP addresses allowed to access the view layer.</p>
<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.display">
<!--[pytunesconnect.Pytunesconnect.display]--><tt class="descname">display</tt><big>(</big><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.display" title="Permalink to this definition">¶</a></dt>
<dd>Called to invoke the built in view layer.</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.displayItemDetail">
<!--[pytunesconnect.Pytunesconnect.displayItemDetail]--><tt class="descname">displayItemDetail</tt><big>(</big><em>appleid</em>, <em>offset</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.displayItemDetail" title="Permalink to this definition">¶</a></dt>
<dd><p>Called to display the item details page including charts. You
shouldn&#8217;t need to call this manually or edit it unless you
would like to customize the view layer further.  appleid is the
Apple ID of the item details should be displayed for. Offset controls
how far back in time data is shown returned for, it should be a unix
timestamp as a string or a date string in the form of YYYY-MM-DD.</p>
<p>The code in this method is a good example of how to use the
data and chart methods in the class.</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.displayMainMenu">
<!--[pytunesconnect.Pytunesconnect.displayMainMenu]--><tt class="descname">displayMainMenu</tt><big>(</big><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.displayMainMenu" title="Permalink to this definition">¶</a></dt>
<dd>Called to display the main menu if using the built in view layer,
you should not need to use this unless you would like to customize
the view layer further.</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItemCountryBreakdown">
<!--[pytunesconnect.Pytunesconnect.getItemCountryBreakdown]--><tt class="descname">getItemCountryBreakdown</tt><big>(</big><em>appleid</em>, <em>offset='0'</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItemCountryBreakdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of lists containing information on the total number of
new downloads of a given application id (Apple ID).  Information is
grouped by country for worldwide downloads. Offset controls
how far back in time data is shown returned for, it should be a unix
timestamp as a string or a date string in the form of YYYY-MM-DD.</p>
<p>The first list returned in the list contains headers with names of
info in the lists that follow it.</p>
<p>Example return</p>
<p>[[&#8220;Country&#8221;, &#8220;Units&#8221;],[&#8220;US&#8221;, &#8220;200&#8221;],[&#8220;UK&#8221;, &#8220;150&#8221;]]</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItemDetail">
<!--[pytunesconnect.Pytunesconnect.getItemDetail]--><tt class="descname">getItemDetail</tt><big>(</big><em>appleid</em>, <em>offset='0'</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItemDetail" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of lists containing information on the number of
new downloads and reinstalls of a given application id (Apple ID).  Information is
grouped by date for worldwide downloads in order by date. Offset controls
how far back in time data is shown returned for, it should be a unix
timestamp as a string or a date string in the form of YYYY-MM-DD.</p>
<p>The first list returned in the list contains headers with names of
info in the lists that follow it.</p>
<p>Example return</p>
<p>[[&#8220;Date&#8221;, &#8220;NewDownloads&#8221;, &#8220;Reinstalls&#8221;],[&#8220;2010-02-22&#8221;, &#8220;200&#8221;, &#8220;50&#8221;],[&#8220;2010-02-23&#8221;, &#8220;150&#8221;, &#8220;25&#8221;]]</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItemName">
<!--[pytunesconnect.Pytunesconnect.getItemName]--><tt class="descname">getItemName</tt><big>(</big><em>appleid</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItemName" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the vendor id associated with the apple id as a string</p>
<p>Example Return:</p>
<p>&#8216;iFart&#8217;</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItemNewDownloads">
<!--[pytunesconnect.Pytunesconnect.getItemNewDownloads]--><tt class="descname">getItemNewDownloads</tt><big>(</big><em>appleid</em>, <em>offset='0'</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItemNewDownloads" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of lists containing information on the number of
new downloads of a given application id (Apple ID).  Information is
grouped by date for worldwide downloads in order by date. Offset controls
how far back in time data is shown returned for, it should be a unix
timestamp as a string or a date string in the form of YYYY-MM-DD.</p>
<p>The first list returned in the list contains headers with names of
info in the lists that follow it.</p>
<p>Example return</p>
<p>[[&#8220;Date&#8221;, &#8220;NewDownloads&#8221;],[&#8220;2010-02-22&#8221;, &#8220;200&#8221;],[&#8220;2010-02-23&#8221;, &#8220;150&#8221;]]</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItemReinstalls">
<!--[pytunesconnect.Pytunesconnect.getItemReinstalls]--><tt class="descname">getItemReinstalls</tt><big>(</big><em>appleid</em>, <em>offset='0'</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItemReinstalls" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of lists containing information on the number of
reinstalls of a given application id (Apple ID).  Information is
grouped by date for worldwide downloads in order by date. Offset controls
how far back in time data is shown returned for, it should be a unix
timestamp as a string or a date string in the form of YYYY-MM-DD.</p>
<p>The first list returned in the list contains headers with names of
info in the lists that follow it.</p>
<p>Example return</p>
<p>[[&#8220;Date&#8221;, &#8220;Reinstalls&#8221;],[&#8220;2010-02-22&#8221;, &#8220;200&#8221;],[&#8220;2010-02-23&#8221;, &#8220;150&#8221;]]</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItemRevenue">
<!--[pytunesconnect.Pytunesconnect.getItemRevenue]--><tt class="descname">getItemRevenue</tt><big>(</big><em>appleid</em>, <em>offset='0'</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItemRevenue" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of lists containing information on the revenue
generated by a given application id (Apple ID).  Information is
grouped by date and by currency type. Offset controls
how far back in time data is shown returned for, it should be a unix
timestamp as a string or a date string in the form of YYYY-MM-DD.</p>
<p>The first list returned in the list contains headers with names of
info in the lists that follow it.</p>
<p>Example return</p>
<p>[[&#8220;Date&#8221;,&#8221;Revenue&#8221;,&#8221;Units Sold&#8221;,&#8221;Currency&#8221;],[&#8220;2010-02-22&#8221;, &#8220;20.70&#8221;, &#8220;20&#8221;,&#8221;USD&#8221;],[&#8220;2010-02-22&#8221;, &#8220;15.30&#8221;, &#8220;30&#8221;,&#8221;EUR&#8221;]]</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getItems">
<!--[pytunesconnect.Pytunesconnect.getItems]--><tt class="descname">getItems</tt><big>(</big><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getItems" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dicationary of vendor IDs and apple ids currently
in the database.  The Key is the vendor id and the value is the apple
identifier.</p>
<p>The returned dictionary will be in the form {{&#8216;Facebook&#8217;:&#8216;12345687&#8217;},{&#8216;Pandora&#8217;:&#8216;1234568&#8217;}}</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.getMaxDateForOffset">
<!--[pytunesconnect.Pytunesconnect.getMaxDateForOffset]--><tt class="descname">getMaxDateForOffset</tt><big>(</big><em>offset</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.getMaxDateForOffset" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.parseReport">
<!--[pytunesconnect.Pytunesconnect.parseReport]--><tt class="descname">parseReport</tt><big>(</big><em>fname</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.parseReport" title="Permalink to this definition">¶</a></dt>
<dd><p>Used to parse the report downloaded by appdailysales.py and
insert the data into the mySQL database.</p>
<p>This will be called automatically when pytunesconnect.py is
executed with the -d option at the command line.</p>
</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.printError">
<!--[pytunesconnect.Pytunesconnect.printError]--><tt class="descname">printError</tt><big>(</big><em>message</em>, <em>detail</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.printError" title="Permalink to this definition">¶</a></dt>
<dd>Called by the view layer to print any errors as HTML</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.printFooter">
<!--[pytunesconnect.Pytunesconnect.printFooter]--><tt class="descname">printFooter</tt><big>(</big><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.printFooter" title="Permalink to this definition">¶</a></dt>
<dd>Used by the view layer to print a standard HTML footer across all pages.</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.printHeader">
<!--[pytunesconnect.Pytunesconnect.printHeader]--><tt class="descname">printHeader</tt><big>(</big><em>title</em>, <em>header=''</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.printHeader" title="Permalink to this definition">¶</a></dt>
<dd>Used by the view layer to print a standardized HTML header across all pages</dd></dl>

<dl class="method">
<dt id="pytunesconnect.Pytunesconnect.printTable">
<!--[pytunesconnect.Pytunesconnect.printTable]--><tt class="descname">printTable</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#pytunesconnect.Pytunesconnect.printTable" title="Permalink to this definition">¶</a></dt>
<dd>This method will print a list of lists as a standard HTML table.
This method is used by the view layer.</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-pytunescharts">
<h2 id="module-pytunescharts">pytunescharts.py Documentation<a class="headerlink" href="#module-pytunescharts" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="pytunescharts.getDygraph">
<!--[pytunescharts.getDygraph]--><tt class="descclassname">pytunescharts.</tt><tt class="descname">getDygraph</tt><big>(</big><em>data</em>, <em>divname</em>, <em>width</em>, <em>height</em><big>)</big><a class="headerlink" href="#pytunescharts.getDygraph" title="Permalink to this definition">¶</a></dt>
<dd><p>Called to generate an interactive dygraph (<a class="reference external" href="http://danvk.org/dygraphs/">http://danvk.org/dygraphs/</a>)</p>
<p>Parameters:</p>
<p>data - A list of lists containing the information to be graphed - example: [[&#8220;Date&#8221;, &#8220;Reinstalls&#8221;],[&#8220;2010-02-22&#8221;, &#8220;200&#8221;],[&#8220;2010-02-23&#8221;, &#8220;150&#8221;]]</p>
<p>divname - A string that the div the chart is in will be named.  If you are displaying multiple dygraphs on a page they must have unique div names.</p>
<p>width - A string, the width in pixels of the chart generated</p>
<p>height - A string, the height of the chart generated in pixels</p>
<p>Returns (touple, two strings):</p>
<p>head - HTML to be placed in the &lt;head&gt; tag of the page where the chart is displated</p>
<p>body - HTML DIV tag to be placed in the body wherever the chart should appear.</p>
</dd></dl>

<dl class="function">
<dt id="pytunescharts.getGoogleIntensityMap">
<!--[pytunescharts.getGoogleIntensityMap]--><tt class="descclassname">pytunescharts.</tt><tt class="descname">getGoogleIntensityMap</tt><big>(</big><em>data</em>, <em>divname</em>, <em>columntypes</em><big>)</big><a class="headerlink" href="#pytunescharts.getGoogleIntensityMap" title="Permalink to this definition">¶</a></dt>
<dd><p>Called to generate an intensity map (<a class="reference external" href="http://code.google.com/apis/visualization/documentation/gallery/intensitymap.html">http://code.google.com/apis/visualization/documentation/gallery/intensitymap.html</a>)</p>
<p>Parameters:</p>
<p>data - A list of lists containing the information to be graphed - example: [[&#8220;Country&#8221;, &#8220;Units&#8221;],[&#8220;US&#8221;, &#8220;200&#8221;],[&#8220;UK&#8221;, &#8220;150&#8221;]]</p>
<p>divname - A string that the div the chart is in will be named.  If you are displaying multiple dygraphs on a page they must have unique div names.</p>
<p>columntypes - A list of strings describing the data types of the columns in data.  Example: [&#8220;string&#8221;, &#8220;number&#8221;]</p>
<p>Returns (touple, two strings):</p>
<p>head - HTML to be placed in the &lt;head&gt; tag of the page where the chart is displated</p>
<p>body - HTML DIV tag to be placed in the body wherever the chart should appear.</p>
</dd></dl>

<dl class="function">
<dt id="pytunescharts.getGoogleTable">
<!--[pytunescharts.getGoogleTable]--><tt class="descclassname">pytunescharts.</tt><tt class="descname">getGoogleTable</tt><big>(</big><em>data</em>, <em>divname</em>, <em>columntypes</em><big>)</big><a class="headerlink" href="#pytunescharts.getGoogleTable" title="Permalink to this definition">¶</a></dt>
<dd><p>Called to generate an interactive javascript table (<a class="reference external" href="http://code.google.com/apis/visualization/documentation/gallery/table.html">http://code.google.com/apis/visualization/documentation/gallery/table.html</a>)</p>
<p>Parameters:</p>
<p>data - A list of lists containing the information to be graphed - example: [[&#8220;Date&#8221;,&#8221;Revenue&#8221;,&#8221;Units Sold&#8221;,&#8221;Currency&#8221;],[&#8220;2010-02-22&#8221;, &#8220;20.70&#8221;, &#8220;20&#8221;,&#8221;USD&#8221;],[&#8220;2010-02-22&#8221;, &#8220;15.30&#8221;, &#8220;30&#8221;,&#8221;EUR&#8221;]]</p>
<p>divname - A string that the div the chart is in will be named.  If you are displaying multiple dygraphs on a page they must have unique div names.</p>
<p>columntypes - A list of strings describing the data types of the columns in data.  Example: [&#8220;string&#8221;, &#8220;number&#8221;, &#8220;number&#8221;, &#8220;string&#8221;]</p>
<p>Returns (touple, two strings):</p>
<p>head - HTML to be placed in the &lt;head&gt; tag of the page where the chart is displated</p>
<p>body - HTML DIV tag to be placed in the body wherever the chart should appear.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3>Table Of Contents</h3>
            <ul>
<li><a class="reference external" href="">Code Documentation</a><ul>
<li><a class="reference external" href="#module-pytunesconnect">pytunesconnect Class Documentation</a></li>
<li><a class="reference external" href="#module-pytunescharts">pytunescharts.py Documentation</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="webservice.html" title="previous chapter">Web Service Documentation</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/code.txt">Show Source</a></li>
            </ul>
            <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="webservice.html" title="Web Service Documentation"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">pyTunesConnect v1.0.1 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Jonathan Carroll.
      Last updated on May 06, 2010.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    </div>
  </body>
</html>